<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 */
class Attachedcate_model extends MY_Model{
	
	var $_pre;

	public function __construct() {
		parent::__construct();
		if (!empty($this->_d['lg'])) $this->_pre = "_" . $this->_d['lg'];
		$this->tbl = 'ey_attach_cate' . $this->_pre;
		$this->tbl_key = 'attachcateid';
		$this->tbl_ext = '';
		$this->tb2 = 'ey_attach_detail' . $this->_pre;
	}

	public function LL($detailid,$action = '')
	{
		if (is_array($detailid))
		{
			$strdetailid = implode(',',$detailid);
		}
		else
		{
			$strdetailid = $detailid;
		}

		$sql = "select a.detailid, b.* from ".$this->tbl . " as a left join " .$this->tb2 . " as b on (a.attachcateid = b.attachcateid) where a.detailid in (" . $strdetailid . ")";

		if ($action != '') $sql = $sql . " and action = '" .$action."'";
		//print_r($sql);
		$query = $this->db->query($sql);
		return $query->result_array();
	}

	public function getdetail($detailid)
	{
		$attached = $this->LL($detailid);
		if (!empty($attached))
		{

			return array2group($attached, 'detailid');
		}
		else
		{
			return false;
		}
	}

}
